package com.example.controller.handle;

import com.alibaba.dubbo.config.annotation.Reference;
import com.example.common.api.reader.ReaderService;

import com.example.common.model.Article;
import com.example.common.model.Catalog;
import com.example.common.otherObject.Articles;
import org.springframework.stereotype.Controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

@Controller
public class ReaderController {

    @Reference(version = "1.0.0")
    private ReaderService  readerService;

    /**
     * 获取数据的数据返回到首页
     * @param model
     * @return index界面
     */
    @GetMapping("/index.do")
    public String showIndex(){

       return "index";
    }
    @GetMapping("show_catalog.do")
    @ResponseBody
    public List<Catalog> getCatalog(){
        List<Catalog> catalog=readerService.showCatalog();
        return catalog;
    }

    @GetMapping("show_articel.do")
    @ResponseBody
    public  List<Articles> getArticle(@RequestParam(defaultValue = "5",value = "pn") Integer pn){
        List<Articles> article=readerService.showArticle(pn);
        return article;
    }
}
